/*
	server： 保存用户数据
*/

var http = require("http");
var express = require("express");
var sio = require("socket.io");

var app = express();
var server = http.createServer(app).listen(1337);

app.get('/', function(req, res) {
	res.sendfile('./9_getSetClient.html');
});

var socketSer = sio.listen(server);

socketSer.on('connection', function(socket) {

	socket.on('set nickname', function(name) {
		socket.set('nickname', name, function() {
			socket.emit('send nickname', name);
		});
	});

	socket.on('get nickname', function() {
		socket.get('nickname', function(err, name) {
			if (err)
				socket.emit('err', err.message);
			else
				socket.emit('send nickname', name);
		});
	});

});